home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / Preinstalled MacPerl (FAT) / t / op / regexp.t < prev    next >
Encoding:
Text File  |  1995-10-31  |  1.1 KB  |  38 lines  |  [TEXT/McPL]

  1. #!./perl
  2.  
  3. # $RCSfile: regexp.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:20 $
  4.  
  5. # open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests')
  6. open(TESTS,':op:re_tests') || open(TESTS,':t:op:re_tests') || open(TESTS,'re_tests')
  7.     || die "Can't open re_tests";
  8. while (<TESTS>) { }
  9. $numtests = $.;
  10. close(TESTS);
  11.  
  12. print "1..$numtests\n";
  13. # open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests')
  14. open(TESTS,':op:re_tests') || open(TESTS,':t:op:re_tests') || open(TESTS,'re_tests')
  15.     || die "Can't open re_tests";
  16. $| = 1;
  17. while (<TESTS>) {
  18.     ($pat, $subject, $result, $repl, $expect) = split(/[\t\n]/,$_);
  19.     $input = join(':',$pat,$subject,$result,$repl,$expect);
  20.     $pat = "'$pat'" unless $pat =~ /^'/;
  21.     eval "\$match = (\$subject =~ m$pat); \$got = \"$repl\";";
  22.     if ($result eq 'c') {
  23.     if ($@ ne '') {print "ok $.\n";} else {print "not ok $.\n";}
  24.     }
  25.     elsif ($result eq 'n') {
  26.     if (!$match) {print "ok $.\n";} else {print "not ok $. $input => $got\n";}
  27.     }
  28.     else {
  29.     if ($match && $got eq $expect) {
  30.         print "ok $.\n";
  31.     }
  32.     else {
  33.         print "not ok $. $input => $got\n";
  34.     }
  35.     }
  36. }
  37. close(TESTS);
  38.